<template>
  <div class="search">
    <div class="search-wrapper">
      <input type="text" class="searchInput" v-model="search" placeholder="搜索" />
      <span class="icon iconfont icon-sousuo"></span>
      <span class="icon iconfont icon-delete" v-show="haveText" @click="del()"></span>
    </div>
    <div class="add-wrapper">
      <span class="icon iconfont icon-tianjia" title="添加朋友" @click="showWindow()"></span>
      <div class="searchWindow" v-show="flag">
        <SearchWindow @closeWindow="closeWindow()"></SearchWindow>
      </div>
    </div>
  </div>
</template>

<script>
import { mapActions } from "vuex";
import SearchWindow from "../search/searchFriend";

export default {
  components: {
    SearchWindow
  },
  data() {
    return {
      search: "",
      flag: false
    };
  },
  methods: {
    ...mapActions(["changeSearch"]),
    del() {
      this.search = "";
    },
    showWindow() {
      this.flag = true;
    },
    closeWindow() {
      this.flag = false;
    }
  },
  computed: {
    haveText() {
      if (this.search != "") return true;
      return false;
    }
  },
  watch: {
    search() {
      this.changeSearch(this.search);
    }
  }
};
</script>

<style scoped>
.search {
  display: flex;
  width: 100%;
  padding: 21px 12px 12px 12px;
  box-sizing: border-box;
}

.search-wrapper {
  position: relative;
  display: flex;
  flex: 1;
  min-width: 0;
  height: 26px;
  box-sizing: border-box;
  border-radius: 5px;
  background-color: #e5e3e2;
}

.searchInput {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  box-sizing: border-box;
  padding: 6px 0 6px 25px;
  border: 2px solid #dbd9d8;
  border-radius: 5px;
  background-color: #dbd9d8;
  outline: none;
}

.searchInput:focus {
  background-color: #f2efee;
}

.icon-sousuo {
  display: inline-block;
  position: absolute;
  width: 24px;
  height: 26px;
  font-size: 17px;
  line-height: 26px;
  text-align: center;
  color: #636363;
}

.add-wrapper {
  position: relative;
  width: 27px;
  height: 27px;
  margin-left: 12px;
  box-sizing: border-box;
  border-radius: 5px;
  background-color: #dbd9d8;
}

.icon-tianjia {
  display: inline-block;
  width: 28px;
  height: 27px;
  line-height: 27px;
  font-size: 27px;
  text-align: center;
  color: #595959;
}

.searchWindow {
  position: absolute;
  top: -21px;
  left: -271px;
  width: 860px;
  height: 600px;
  background-color: rgba(94, 94, 94, 0.5);
  z-index: 1;
}
</style>